<template>
    <div class="ui centered form">
        <div class="ui header">修改密码</div>
        <div class="field">
            <label for="">老密码</label>
            <input type="password"  v-focus v-model="vo.pwd_old" placeholder="请输入老密码">
        </div>
        <div class="field">
            <label for="">新密码</label>
            <input type="password"  v-model="vo.pwd" placeholder="请输入新密码">
        </div>
        <div class="field">
            <label for="">新密码确认</label>
            <input type="password"  v-model="vo.pwd_confirm" placeholder="请再次输入新密码">
        </div>
        <p >
            <button type="submit" @click="do_change" :class="{loading:onsubmit}" class="ui sub_btn primary button">提 交</button>
            <button type="submit" class="ui sub_btn button">取消</button>
        </p>
    </div>
</template>

<script>
    import tool from 'src/util/tool';
    import util from '_util/index';
    import logic from '_logic';
    export default {
        props: [],
        data(){
            return {
                vo: {},
                onsubmit:false
            }

        },
        watch: {
        },
        created(){
        },
        methods: {
            do_change(){
              if(this.onsubmit)
                return;
                let vo = this.vo;
              if(!vo.pwd_old||!/^.+$/.test(vo.pwd_old)) {
                  util.showMsg(this, 'warning', '请输入老密码！')
                  return;
              }
              if(!vo.pwd||!/^.+$/.test(vo.pwd)) {
                  util.showMsg(this, 'warning', '请输入新密码！')
                  return;
              }
              if(vo.pwd!=vo.pwd_confirm) {
                  util.showMsg(this, 'warning', '两次输入的新密码不一致！')
                  return;
              }
              if(/\S{6,20}/.test(vo.pwd)&&/[\D+]/.test(vo.pwd)){
                  let url = tool.getApi(this, 'Op', 'change_pwd');
                  this.onsubmit=true;

                  util.http.SR(this, url, vo,'', (rs) => {
                      this.onsubmit=false;
                  },{show_err:true},()=>{
                      this.onsubmit=false;
                  });

                  setTimeout(() => {
                      this.onsubmit=false;
                  }, 1000 * 5);
              }else{
                  util.showMsg(this, 'warning', '密码规则：8-20位数字，字母与符号组合')
              }

            },
        }
    }
</script>

<style lang="less" rel="stylesheet/less" scoped>
</style>
